Centos6.5 x86_64システムでKVM(kernel-based virtual machine)をインストールするメモ

操作手順:

準備作業
iptablesとselinuxを閉じる
[root@startnews24 ~]# /etc/init.d/iptables stop
[root@startnews24 ~]# chkconfig iptables off
[root@startnews24 ~]# chkconfig –list iptables
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@startnews24 ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
[root@startnews24 ~]# setenforce 0

1.kvm仮想マシンをインストールする

1.1 KVMをサポートしているかどうかを判断するためにCPUを確認
[root@startnews24 ~]# grep “flags" /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt xsave avx hypervisor lahf_lm arat epb xsaveopt pln pts dts tpr_shadow vnmi ept vpid

1.2 kvmおよび必要に応じてソフトウェアパッケージをインストールする

[root@startnews24 ~]# yum install -y kvm virt-* libvirts bridge-utils qemu-img

1.3 kvmモジュールをロード
[root@startnews24 ~]# modprobe kvm-intel
[root@startnews24 ~]# lsmod | grep kvm
kvm_intel 54285 0
kvm 333172 1 kvm_intel

1.4 OSが再起動してKVMがロードされているかどうかを確認
[root@startnews24 ~]# reboot
[root@startnews24 ~]# lsmod | grep kvm
kvm_intel 54285 0
kvm 333172 1 kvm_intel

1.5 仮想マシンのリストを表示
[root@startnews24 ~]# virsh list
Id Name State

1.6 eth0、br0を設定
[root@startnews24 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:33:B3:E5
TYPE=Ethernet
UUID=142284ae-3173-4b0a-80d8-437c26a96719
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
BRIDGE=br0
[root@startnews24 ~]# more /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
HWADDR=00:0C:29:33:B3:E5
TYPE=Bridge
UUID=142284ae-3173-4b0a-80d8-437c26a96719
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.0.1.149
NETMASK=255.255.255.0
GATEWAY=10.0.1.1
[root@startnews24 ~]# /etc/init.d/network restart

1.7 すべてのブリッジインタフェースを確認
[root@startnews24 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c2933b3e5 no eth0
virbr0 8000.525400d969b8 yes virbr0-nic

1.8 VNCサーバー側の設定ファイルを変更
[root@startnews24 ~]# vim /etc/libvirt/qemu.conf
vnc_listen = “0.0.0.0"  //#を削除

1.9 libvirtdとmessagebusが再起動
[root@startnews24 ~]# /etc/init.d/libvirtd restart
Stopping libvirtd daemon: [ OK ]
Starting libvirtd daemon: libvirtd: initialization failed [FAILED]
解決対策:
[root@startnews24 libvirt]# echo “export LC_ALL=en_US.UTF-8" >> /etc/profile
[root@startnews24 libvirt]# source /etc/profile
[root@startnews24 libvirt]# /etc/init.d/libvirtd restart
Stopping libvirtd daemon: [FAILED]
Starting libvirtd daemon: 2014-08-15 16:14:18.595+0000: 2429: info : libvirt version: 0.10.2, package: 29.el6_5.11 (CentOS BuildSystem <http://bugs.centos.org>, 2014-07-31-18:52:08, c6b8.bsys.dev.centos.org)
2014-08-15 16:14:18.595+0000: 2429: warning : virGetHostname:2294 : getaddrinfo failed for 'startnews24’: Name or service not known
[ OK ]
[root@startnews24 ~]# /etc/init.d/messagebus restart
Stopping system message bus: [ OK ]
Starting system message bus: [ OK ]

2.ホストサーバーでkvmを作成、インストールする

2.1 イメージファイルディレクトリと仮想ディスク格納ディレクトリを作成
[root@startnews24 ~]# mkdir /iso
[root@startnews24 ~]# mkdir -p /data/kvmdisk

2.2 CentOS6.5システムイメージファÿいるをisoディレクトリの下でコピー
[root@startnews24 ~]# dd if=/dev/cdrom of=/iso/Centos6.iso
8726528+0 records in
8726528+0 records out
4467982336 bytes (4.5 GB) copied, 298.268 s, 15.0 MB/s

2.3 kvm仮想マシンのでディスクファイルを作成
[root@startnews24 ~]# cd /etc/libvirt/
[root@startnews24 libvirt]# qemu-img create -f qcow2 -o preallocation=metadata kvm_mode.img 10G
Formatting 'kvm_mode.img’, fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 preallocation=’metadata’

2.4 仮想マシンをインストールする

[root@startnews24 libvirt]# virt-install –name=kvm_mode_5566 –ram 1024 –vcpus=1 -f /etc/libvirt/kvm_mode.img –cdrom=/iso/Centos6.iso –graphics vnc,listen=0.0.0.0,port=7788 –force –autostart

Starting install…
ERROR internal error Process exited while reading console log output: char device redirected to /dev/pts/2
qemu-kvm: -drive file=/etc/libvirt/kvm_mode.img,if=none,id=drive-ide0-0-0,format=raw,cache=none: could not open disk image /etc/libvirt/kvm_mode.img: Permission denied

Domain installation does not appear to have been successful.
If it was, you can restart your domain by running:
virsh –connect qemu:///system start kvm_mode_5566
otherwise, please restart your installation.

解決対策:
[root@startnews24 libvirt]# chmod -R 777 /etc/libvirt
[root@startnews24 libvirt]# virt-install –name=kvm_mode_5566 –ram 1024 –vcpus=1 -f /etc/libvirt/kvm_mode.img –cdrom=/iso/Centos6.iso –graphics vnc,listen=0.0.0.0,port=7788 –force –autostart

Starting install…
Creating domain… | 0 B 00:00
Cannot open display:
Run 'virt-viewer –help’ to see a full list of available command line options
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
3.VNCクライアントからKVMに接続、IPを設定
 3.1 VNCで接続
[root@startnews24 ~]# virsh
Welcome to virsh, the virtualization interactive terminal.

Type: 'help’ for help with commands
'quit’ to quit

virsh # list –all
Id Name State
—————————————————-
– kvm_mode_5566 shut off

virsh # start kvm_mode_5566
Domain kvm_mode_5566 started

3.2 IPを設定

[root@kvm-mode-7788 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
MACADDR=52:54:00:80:7E:A5
TYPE=Ethernet
UUID=7d042162-53e9-4ef1-ba2f-bf3b892bb353
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.0.1.108
NETMASK=255.255.255.0
GATEWAY=10.0.1.1
[root@kvm-mode-7788 ~]# ping www.google.com
PING www.arkgame.com (119.75.218.77) 56(84) bytes of data.
64 bytes from www.google.com (119.75.218.77): icmp_seq=1 ttl=54 time=3.05 ms
64 bytes from www.google.com (119.75.218.77): icmp_seq=2 ttl=54 time=4.82 ms
64 bytes from www.google.com (119.75.218.77): icmp_seq=3 ttl=54 time=3.72 ms
^C
— www.arkgame.com ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2252ms
rtt min/avg/max/mdev = 3.055/3.866/4.822/0.730 ms

3.3 kvmステータスを確認
[root@taokey ~]# virsh
Welcome to virsh, the virtualization interactive terminal.

Type: 'help’ for help with commands
'quit’ to quit

virsh # list –all
Id Name State
—————————————————-
1 kvm_mode_5566 running

virsh #

Linux

Posted by arkgame